package pers.cz.postgirl.adapter.eform;

import pers.cz.postgirl.adapter.AbstractTransformer;
import pers.cz.postgirl.config.EvenType;
import pers.cz.postgirl.core.EnhanceModel;

/**
 * @program: postgirl-client
 * @description: ef-orm框架基础数据库操作
 * @author: Cheng Zhi
 * @create: 2023-08-05 10:22
 **/
public class EformDaoCrudPlugin extends AbstractTransformer {


    @Override
    public void loadEnhanceModel() {
        enhanceModel = EnhanceModel.builder()
                .classPattern("com.ailk.easyframe.web.common.dal.AbstractDaoCrudSupport")
                .methodPatterns(getMethodPattern())
                .build();
    }

    private EnhanceModel.MethodPattern[] getMethodPattern() {

        EnhanceModel.MethodPattern findAndPage = EnhanceModel.MethodPattern.builder()
                .methodName("findAndPage")
                .paramTypes(new String[] {"java.lang.reflect.Type","int","int"})
                .evenTypes(new EvenType[] {EvenType.BEFORE, EvenType.RETURN})
                .build();

        EnhanceModel.MethodPattern insert = EnhanceModel.MethodPattern.builder()
                .methodName("insert")
                .paramTypes(new String[] {"java.lang.reflect.Type"})
                .evenTypes(new EvenType[] {EvenType.BEFORE, EvenType.RETURN})
                .build();

        EnhanceModel.MethodPattern insertWithoutCascade = EnhanceModel.MethodPattern.builder()
                .methodName("insertWithoutCascade")
                .paramTypes(new String[] {"java.lang.reflect.Type"})
                .evenTypes(new EvenType[] {EvenType.BEFORE, EvenType.RETURN})
                .build();

        EnhanceModel.MethodPattern merge = EnhanceModel.MethodPattern.builder()
                .methodName("merge")
                .paramTypes(new String[] {"java.lang.reflect.Type"})
                .evenTypes(new EvenType[] {EvenType.BEFORE, EvenType.RETURN})
                .build();

        EnhanceModel.MethodPattern update = EnhanceModel.MethodPattern.builder()
                .methodName("update")
                .paramTypes(new String[] {"java.lang.reflect.Type"})
                .evenTypes(new EvenType[] {EvenType.BEFORE, EvenType.RETURN})
                .build();

        EnhanceModel.MethodPattern updateWithoutCascade = EnhanceModel.MethodPattern.builder()
                .methodName("updateWithoutCascade")
                .paramTypes(new String[] {"java.lang.reflect.Type"})
                .evenTypes(new EvenType[] {EvenType.BEFORE, EvenType.RETURN})
                .build();

        EnhanceModel.MethodPattern remove = EnhanceModel.MethodPattern.builder()
                .methodName("remove")
                .paramTypes(new String[] {"java.lang.reflect.Type"})
                .evenTypes(new EvenType[] {EvenType.BEFORE, EvenType.RETURN})
                .build();

        EnhanceModel.MethodPattern removeCascade = EnhanceModel.MethodPattern.builder()
                .methodName("removeCascade")
                .paramTypes(new String[] {"java.lang.reflect.Type"})
                .evenTypes(new EvenType[] {EvenType.BEFORE, EvenType.RETURN})
                .build();

        EnhanceModel.MethodPattern load = EnhanceModel.MethodPattern.builder()
                .methodName("load")
                .paramTypes(new String[] {"java.lang.reflect.Type"})
                .evenTypes(new EvenType[] {EvenType.BEFORE, EvenType.RETURN})
                .build();

        EnhanceModel.MethodPattern loadWithoutCascade = EnhanceModel.MethodPattern.builder()
                .methodName("loadWithoutCascade")
                .paramTypes(new String[] {"java.lang.reflect.Type"})
                .evenTypes(new EvenType[] {EvenType.BEFORE, EvenType.RETURN})
                .build();

        EnhanceModel.MethodPattern findByExample = EnhanceModel.MethodPattern.builder()
                .methodName("findByExample")
                .paramTypes(new String[] {"java.lang.reflect.Type"})
                .evenTypes(new EvenType[] {EvenType.BEFORE, EvenType.RETURN})
                .build();

        EnhanceModel.MethodPattern find = EnhanceModel.MethodPattern.builder()
                .methodName("find")
                .paramTypes(new String[] {"java.lang.reflect.Type"})
                .evenTypes(new EvenType[] {EvenType.BEFORE, EvenType.RETURN})
                .build();

        EnhanceModel.MethodPattern findWithoutCascade = EnhanceModel.MethodPattern.builder()
                .methodName("findWithoutCascade")
                .paramTypes(new String[] {"java.lang.reflect.Type"})
                .evenTypes(new EvenType[] {EvenType.BEFORE, EvenType.RETURN})
                .build();
        return new EnhanceModel.MethodPattern[] {
                findAndPage,
                insert,
                insertWithoutCascade,
                merge,
                update,
                updateWithoutCascade,
                remove,
                removeCascade,
                load,
                loadWithoutCascade,
                findByExample,
                find,
                findWithoutCascade};
    }
}
